package com.pjj.projectservice.controller;

import com.pjj.projectservice.entity.ProjectNote;
import com.pjj.projectservice.service.ProjectNoteService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author 76004
 * @apiNote
 * @date 2023/2/17 16:50
 */
@RestController
@RequestMapping("/projectNote")
public class ProjectNoteController {
    @Autowired
    private ProjectNoteService projectNoteService;

    @ApiOperation(value = "按照id查询日志")
    @GetMapping("/selectById")
    public Object selectById(long projectNoteId){
        return projectNoteService.selectById(projectNoteId);
    }

    @ApiOperation(value = "添加日志")
    @PostMapping("/insert")
    public Object insert(@RequestBody ProjectNote projectNote, @RequestBody MultipartFile multipartFile) throws IOException {
        return projectNoteService.insertProjectNote(projectNote,multipartFile);
    }

    @ApiOperation(value = "按照id删除日志")
    @DeleteMapping("/deleteById")
    public Object deleteProjectNoteById(long projectNoteId){
        return projectNoteService.deleteById(projectNoteId);
    }

    @ApiOperation(value = "更新某一条日志")
    @PutMapping("/update")
    public Object update(@RequestBody ProjectNote projectNote){
        return projectNoteService.updateProjectNote(projectNote);
    }

    @ApiOperation(value = "查询某项目下的日志")
    @GetMapping("/selectByProjectId")
    public Object selectByProjectId(long projectId, int pageNum,int pageSize){
        return projectNoteService.selectByProjectId(projectId,pageNum,pageSize);
    }

    @ApiOperation(value = "添加图片到数据库")
    @PostMapping("/insertImage")
    public void insertImage(String url, MultipartFile multipartFile) throws IOException {
        projectNoteService.saveImage(url,multipartFile);
    }







}
